﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Models;
using BLL;

namespace AGVControlSystemPro
{
    public partial class FrmProjectNameEdit : Form
    {
        public FrmProjectNameEdit(FileNameAddress objFileNameAddress)
        {
            InitializeComponent();
            //数据加载
            this.txtID.Text = objFileNameAddress.ID.ToString();
            this.txtName.Text = objFileNameAddress.FileName;
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.txtName.Text.Trim().Length == 0)
            {
                if (CommonMethods.LanguageId == 3) MessageBox.Show("工事の名称は空けてはならない！", "情報のヒント");
                else MessageBox.Show("工程名称不能为空！", "修改提示");
                this.txtName.Focus();
                return;
            }
            #endregion
            //数据封装
            FileNameAddress objFileNameAddress = new FileNameAddress() 
            {
                ID = Convert.ToInt32(this.txtID.Text.Trim()),
                FileName = this.txtName.Text.Trim()
            };
            //后台数据访问
            try
            {
                int result = new FileNameAddressManager().UpdateFileName(objFileNameAddress); //修改数据库数据
                if (result > 0)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                if (CommonMethods.LanguageId == 3) MessageBox.Show("工程文件名称修改失败！错误详细信息：" + ex.Message);
                else MessageBox.Show("工程文件名称修改失败！错误详细信息：" + ex.Message);
                
            }
        }
        
    }
}
